//
//  XMAlbumJigsawAvatarCell.m
//  XiaoMiao
//
//  Created by kinglian_iOS_000 on 2018/2/24.
//  Copyright © 2018年 smallyou. All rights reserved.
//

#import "XMAlbumJigsawAvatarCell.h"
#import "AlbumImageModel.h"

@interface XMAlbumJigsawAvatarCell()
@property (weak, nonatomic) IBOutlet UIButton *deleteButton;
@property (weak, nonatomic) IBOutlet UIButton *seletedTagButton;
@property (weak, nonatomic) IBOutlet UIImageView *avatarImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@end

@implementation XMAlbumJigsawAvatarCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.contentView.backgroundColor = kRGBColor(200, 200, 200);
    
    self.avatarImageView.layer.borderWidth = 1;
    self.avatarImageView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    self.avatarImageView.layer.masksToBounds = YES;
    
    self.deleteButton.app_touchExtendInset = UIEdgeInsetsMake(-10, -10, -10, -10);
    [self.deleteButton addTarget:self action:@selector(deleteButtonDicClick) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setAlbumImageModel:(AlbumImageModel *)albumImageModel {
    _albumImageModel = albumImageModel;
    
    if (albumImageModel.titleStr) {
        
        self.deleteButton.hidden = YES;
        self.seletedTagButton.hidden = YES;
        self.avatarImageView.hidden = YES;
        self.titleLabel.hidden = NO;
        self.titleLabel.text = albumImageModel.titleStr;
        self.layer.borderColor = kBgColor.CGColor;
        self.layer.borderWidth = 1;
        self.contentView.backgroundColor = kWhiteColor;

    }else{
        
        self.contentView.backgroundColor = kRGBColor(200, 200, 200);

        self.layer.borderColor = kWhiteColor.CGColor;
        self.layer.borderWidth = 0;
        self.titleLabel.hidden = YES;
        self.avatarImageView.hidden = NO;

        [self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:albumImageModel.imageUrl] placeholderImage:nil];
        
        self.seletedTagButton.selected = albumImageModel.isSeleted;
        
        switch (self.albumImageType) {
            case AlbumImageTypeNone: {
                self.deleteButton.hidden = YES;
                self.seletedTagButton.hidden = YES;
            }
                break;
                
            case AlbumImageTypeSeleted: {
                self.deleteButton.hidden = YES;
                self.seletedTagButton.hidden = NO;
                
            }
                break;
                
            case AlbumImageTypeDeleted: {
                self.deleteButton.hidden = NO;
                self.seletedTagButton.hidden = YES;
            }
                break;
        }
    }
    

}

- (void)deleteButtonDicClick {
    if ([self.delegate respondsToSelector:@selector(albumJigsawAvatarCell:didDeletedAlbumImageModel:)]) {
        [self.delegate albumJigsawAvatarCell:self didDeletedAlbumImageModel:self.albumImageModel];
    }
}

+ (NSString *)cellId {
    return @"XMAlbumJigsawAvatarCellId";
}

@end
